﻿using System;

namespace FLH.Enumerations
{
    /// <summary>
    /// This class contains constants and other settings.
    /// </summary>
    public static class EnumExtensions
    {

        #region Enum string extension method
        /// <summary>
        /// Extension Method: 
        /// Will get the string value for a given enums value, this will only work if you assign the StringValue
        /// attribute to the items in your enum.
        /// This extension will not work if the StringValueAttribute class doesn't exist and you haven't 
        /// decorated the enum values with the [StringValue("TheString")] attribute.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetStringValue(this Enum value)
        {
            // Get the type
            var type = value.GetType();

            // Get fieldinfo for this type
            var fieldInfo = type.GetField(value.ToString());

            // Get the stringvalue attributes
            var attribs = fieldInfo.GetCustomAttributes(
                typeof(StringValueAttribute), false) as StringValueAttribute[];

            // Return the first if there was a match.
            return attribs == null ? null : (attribs.Length > 0 ? attribs[0].StringValue : null);
        }

        /// <summary>
        /// Gets the int value string.
        /// returns the string representation of the selected value.
        /// 1 = "1"
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public static string GetIntValueString(this Enum value)
        {
            return Convert.ToString(value);
        }
        #endregion
    }

    /// <summary>
    /// Custom attribute class: 
    /// This attribute is used to represent a string value for a value in an enum.
    /// </summary>
    public class StringValueAttribute : Attribute
    {

        #region Properties

        /// <summary>
        /// Holds the stringvalue for a value in an enum.
        /// </summary>
        public string StringValue { get; protected set; }

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor used to init a StringValue Attribute
        /// </summary>
        /// <param name="value"></param>
        public StringValueAttribute(string value)
        {
            StringValue = value;
        }

        #endregion
    }

    /// <summary>
    /// This enumeration provides the string representations of the partition keys used by many 
    /// of the table entities.  These are here because we want to used fixed strings without 
    /// hard-coding strings in the code.
    /// This is coordinated to supply the text partition names that represent the Azure entity names
	/// to the code.  The table names are defined in TableStorageSettings.cs
    /// </summary>
	public enum TablePartitionKeys
	{
		///// <summary>
		///// DistrictsTable partitionKey defined for the District Plan Types 2010. The
		///// table name where this partition resides is defined in ApplicationsSettingsManager
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("DistrictPlanTypes10")]
		//DistrictPlanTypes10 = 1,

		///// <summary>
		///// FileInfoTable partitionKey defined for the File Info 2010. The table name 
		///// where this partition resides is defined in ApplicationsSettingsManager
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("FileInfo2010")]
		//FileInfo2010,

		///// <summary>
		///// AppLayersTable partitionKey defined for the Layers 2010. The table name 
		///// where this partition resides is defined in ApplicationsSettingsManager
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("Layers2010")]
		//Layers2010,

		///// <summary>
		///// AllGeo10Table partitionKey defined for the AllGeo 2010. The table name 
		///// where this partition resides is defined in ApplicationsSettingsManager
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("AllGeo2010")]
		//AllGeo2010,

		///// <summary>
		///// AllDictionaryTable partitionKey defined for the AllDictionary 2010. The table name 
		///// where this partition resides is defined in ApplicationsSettingsManager
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("AllDictionary2010")]
		//AllDictionary2010,

		///// <summary>
		///// Aggregate table for all dictionaries except ACS data and the All data.
		///// This is the partition prefix. The suffix is the use type such as "block"
		///// or "parcel" etc.
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("Dictionaries__")]
		//Dictionaries,

		///// <summary>
		///// Aggregate table for all Regions except ACS data and the All data
		///// This is the partition prefix. The suffix is the use type such as "block"
		///// or "parcel" etc.
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("Regions__")]
		//Regions,

		///// <summary>
		///// Aggregate table for all RegionZoom except ACS data and the All data
		///// This is the partition prefix. The suffix is the use type such as "block"
		///// or "parcel" etc.
		///// TableStorageSettings.cs
		///// </summary>
		//[StringValue("RegionsZoom__")]
		//RegionsZoom,

		////ACS data uses internal data as partitionKeys and thus does not appear here

	}

	public enum EventCode
    {
        Info = 1,
        Debug,
        Error,
        Audit,
        Fatal
    }
}
